/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import com.opensymphony.xwork2.ActionSupport;
import java.text.DateFormat;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.News;
import service.NewsService;

/**
 *
 * @author sony
 */
public class IndexAction extends ActionSupport implements ServletRequestAware
{

    private NewsService newsService;
    private HttpServletRequest request;

    @Override
    public String execute() {
        String newsInfo = "";
        List<News> newsList = newsService.getLatestNews(5);
        Iterator<News> it = newsList.listIterator();
        while (it.hasNext()) {
            News tempNews = it.next();
            newsInfo += ("<h1><a href=\"showNewsDetail.action?id="+tempNews.getId()+"\">" + tempNews.getTitle() + "</a></h1>");
            newsInfo += ("<h3>发布时间 " + DateFormat.getInstance().format( tempNews.getTime()) + "</h3>");
            newsInfo += ("<p>" + myUtils.Utils.getSubstring(tempNews.getCotent()) + "<hr class=\"clear-contentunit\" />");
        }
        request.setAttribute("news", newsInfo);
        return SUCCESS;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }


    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }
}
